home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImagePointer / ImagePointer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.6 KB  |  442 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.event.MouseMotionListener;
  14. import java.net.MalformedURLException;
  15. import java.net.URL;
  16. import java.net.URLEncoder;
  17.  
  18. public class ImagePointer extends Applet implements Runnable, MouseListener, MouseMotionListener {
  19.    private Thread thread;
  20.    private Image buffer;
  21.    private Image backImage;
  22.    private Image image;
  23.    // $FF: renamed from: b java.awt.Graphics
  24.    private Graphics field_0;
  25.    private boolean loaded;
  26.    private int wiBack;
  27.    private int heBack;
  28.    private boolean isBackImage;
  29.    private boolean move = true;
  30.    // $FF: renamed from: on boolean
  31.    private boolean field_1 = true;
  32.    // $FF: renamed from: wi int
  33.    private int field_2;
  34.    // $FF: renamed from: he int
  35.    private int field_3;
  36.    private int pause = 50;
  37.    // $FF: renamed from: X int
  38.    private int field_4;
  39.    // $FF: renamed from: Y int
  40.    private int field_5;
  41.    private int wiIm;
  42.    private int heIm;
  43.    private String backImageName;
  44.    private Color backColor;
  45.    private String statusBarText;
  46.    private AudioClip sound;
  47.    private AudioClip clicSound;
  48.    private AudioClip enterSound;
  49.    private boolean loopSound;
  50.    private String link;
  51.    // $FF: renamed from: fm java.awt.FontMetrics
  52.    private FontMetrics field_6;
  53.    private String enterText;
  54.    private boolean isEnterTextEnabled;
  55.    private int wiEnterText;
  56.    private int enterTextHeight;
  57.    private Color enterTextColor;
  58.    private String imageName;
  59.    private boolean isVisible;
  60.    private boolean isIn;
  61.  
  62.    public String getAppletInfo() {
  63.       return "Name: ImagePointer\r\nAuthor: Taiji Software\r\n";
  64.    }
  65.  
  66.    public ImagePointer() {
  67.       ((Component)this).addMouseListener(this);
  68.       ((Component)this).addMouseMotionListener(this);
  69.    }
  70.  
  71.    public void register() {
  72.       try {
  73.          URL u = new URL("http://www.taijisoftware.com");
  74.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  75.       } catch (Exception e) {
  76.          System.out.println(e);
  77.          this.stop();
  78.       }
  79.    }
  80.  
  81.    public void init() {
  82.       String codeBase = null;
  83.  
  84.       try {
  85.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  86.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  87.          codeBase = codeBase.toUpperCase();
  88.       } catch (Exception var9) {
  89.       }
  90.  
  91.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  92.          String regCode = ((Applet)this).getParameter("registration_code");
  93.          if (regCode == null) {
  94.             regCode = ((Applet)this).getParameter("reg_domain");
  95.             if (regCode == null) {
  96.                this.register();
  97.             } else {
  98.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  99.                   codeBase = "WWW." + codeBase;
  100.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  101.                   codeBase = codeBase.substring(4);
  102.                }
  103.  
  104.                char[] chars = new char[codeBase.length()];
  105.                codeBase.getChars(0, codeBase.length(), chars, 0);
  106.                String key = new String("haricot");
  107.                char[] chars2 = new char[key.length()];
  108.                key.getChars(0, key.length(), chars2, 0);
  109.  
  110.                for(int i = 0; i < codeBase.length(); ++i) {
  111.                   int j;
  112.                   if (i >= key.length()) {
  113.                      j = i - key.length() * (i / key.length());
  114.                   } else {
  115.                      j = i;
  116.                   }
  117.  
  118.                   chars[i] += chars2[j];
  119.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  120.                }
  121.  
  122.                String res = new String(chars);
  123.                if (!res.equalsIgnoreCase(regCode)) {
  124.                   this.register();
  125.                }
  126.             }
  127.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  128.             this.register();
  129.          }
  130.       }
  131.  
  132.       this.move = true;
  133.       this.getParameters();
  134.       if (this.sound != null) {
  135.          if (this.loopSound) {
  136.             this.sound.loop();
  137.             return;
  138.          }
  139.  
  140.          this.sound.play();
  141.       }
  142.  
  143.    }
  144.  
  145.    public void getParameters() {
  146.       this.field_2 = ((Component)this).getSize().width;
  147.       this.field_3 = ((Component)this).getSize().height;
  148.       String s = ((Applet)this).getParameter("pause");
  149.       if (s != null) {
  150.          this.pause = Integer.parseInt(s);
  151.       }
  152.  
  153.       this.backImageName = ((Applet)this).getParameter("background_image");
  154.       if (this.backImageName != null) {
  155.          this.isBackImage = true;
  156.       }
  157.  
  158.       this.imageName = ((Applet)this).getParameter("image");
  159.       s = ((Applet)this).getParameter("out_visible");
  160.       if (s != null) {
  161.          if (s.equals("yes")) {
  162.             this.isVisible = true;
  163.          }
  164.       } else {
  165.          this.isVisible = true;
  166.       }
  167.  
  168.       ((Component)this).setBackground(this.getColor("background_color"));
  169.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  170.       s = ((Applet)this).getParameter("sound_name");
  171.       if (s != null) {
  172.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  173.       }
  174.  
  175.       s = ((Applet)this).getParameter("loop_sound");
  176.       if (s != null) {
  177.          if (s.equals("yes")) {
  178.             this.loopSound = true;
  179.          } else {
  180.             this.loopSound = false;
  181.          }
  182.       }
  183.  
  184.       s = ((Applet)this).getParameter("clic_sound_name");
  185.       if (s != null) {
  186.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  187.       }
  188.  
  189.       s = ((Applet)this).getParameter("enter_sound_name");
  190.       if (s != null) {
  191.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  192.       }
  193.  
  194.       this.link = ((Applet)this).getParameter("link");
  195.       this.enterText = ((Applet)this).getParameter("enter_text");
  196.       s = ((Applet)this).getParameter("enter_text_height");
  197.       if (s != null) {
  198.          this.enterTextHeight = Integer.parseInt(s);
  199.       }
  200.  
  201.       this.enterTextColor = this.getColor("enter_text_color");
  202.       if (this.enterTextColor == null) {
  203.          this.enterTextColor = Color.white;
  204.       }
  205.  
  206.    }
  207.  
  208.    public Color getColor(String param) {
  209.       String s = ((Applet)this).getParameter(param);
  210.       if (s != null) {
  211.          if (s.substring(0, 1).equals("#")) {
  212.             s = s.substring(1);
  213.             int i = Integer.parseInt(s, 16);
  214.             return new Color(i);
  215.          } else {
  216.             return null;
  217.          }
  218.       } else {
  219.          return null;
  220.       }
  221.    }
  222.  
  223.    public final void paint(Graphics g) {
  224.       if (this.loaded) {
  225.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  226.          if (this.isBackImage) {
  227.             this.field_0.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
  228.          }
  229.  
  230.          if (this.isVisible && !this.isIn || this.isIn) {
  231.             this.field_0.drawImage(this.image, this.field_4, this.field_5, this);
  232.          }
  233.  
  234.          if (this.isEnterTextEnabled) {
  235.             this.field_0.drawString(this.enterText, (this.field_2 - this.wiEnterText) / 2, this.field_3 / 2);
  236.          }
  237.  
  238.          g.drawImage(this.buffer, 0, 0, this);
  239.       }
  240.  
  241.    }
  242.  
  243.    public final void update(Graphics g) {
  244.       this.paint(g);
  245.    }
  246.  
  247.    public void start() {
  248.       if (this.thread == null) {
  249.          this.move = true;
  250.          this.thread = new Thread(this);
  251.          this.thread.start();
  252.       }
  253.  
  254.    }
  255.  
  256.    public void stop() {
  257.       if (this.thread != null) {
  258.          this.move = false;
  259.          this.thread = null;
  260.       }
  261.  
  262.       if (this.sound != null) {
  263.          this.sound.stop();
  264.       }
  265.  
  266.    }
  267.  
  268.    public void run() {
  269.       if (!this.loaded) {
  270.          MediaTracker tracker = new MediaTracker(this);
  271.          this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.imageName);
  272.          tracker.addImage(this.image, 0);
  273.          if (this.isBackImage) {
  274.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  275.             tracker.addImage(this.backImage, 0);
  276.          }
  277.  
  278.          try {
  279.             tracker.waitForAll();
  280.             this.loaded = !tracker.isErrorAny();
  281.          } catch (Exception e) {
  282.             System.out.println(e);
  283.          }
  284.  
  285.          if (!this.loaded) {
  286.             this.stop();
  287.          }
  288.       }
  289.  
  290.       this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  291.       this.field_0 = this.buffer.getGraphics();
  292.       this.field_0.setColor(this.enterTextColor);
  293.       String fontName = ((Applet)this).getParameter("enter_text_font");
  294.       if (fontName == null) {
  295.          fontName = "TimesRoman";
  296.       }
  297.  
  298.       int style = 1;
  299.       String s = ((Applet)this).getParameter("enter_text_style");
  300.       if (s != null) {
  301.          if (s.equals("bold")) {
  302.             style = 1;
  303.          } else if (s.equals("italic")) {
  304.             style = 2;
  305.          } else if (s.equals("bold_italic")) {
  306.             style = 3;
  307.          } else {
  308.             style = 0;
  309.          }
  310.       }
  311.  
  312.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  313.       this.field_6 = this.field_0.getFontMetrics();
  314.       if (this.enterText != null) {
  315.          this.wiEnterText = this.field_6.stringWidth(this.enterText);
  316.       }
  317.  
  318.       if (this.isBackImage) {
  319.          this.wiBack = this.backImage.getWidth(this);
  320.          this.heBack = this.backImage.getHeight(this);
  321.       }
  322.  
  323.       this.wiIm = this.image.getWidth(this);
  324.       this.heIm = this.image.getHeight(this);
  325.       this.field_4 = this.field_2 / 2 - this.wiIm / 2;
  326.       this.field_5 = this.field_3 / 2 - this.heIm / 2;
  327.  
  328.       while(this.move) {
  329.          while(this.field_1) {
  330.             ((Component)this).repaint();
  331.  
  332.             try {
  333.                Thread.sleep((long)this.pause);
  334.             } catch (InterruptedException var6) {
  335.                this.stop();
  336.             }
  337.  
  338.             if (!this.field_1) {
  339.             }
  340.          }
  341.  
  342.          try {
  343.             Thread.sleep(100L);
  344.          } catch (InterruptedException var4) {
  345.             this.stop();
  346.          }
  347.       }
  348.  
  349.    }
  350.  
  351.    public URL giveURL(String url) {
  352.       try {
  353.          if (url.toUpperCase().startsWith("HTTP")) {
  354.             return new URL(url);
  355.          } else if (url.toUpperCase().startsWith("FTP")) {
  356.             int p = url.indexOf(":");
  357.             int p2 = url.indexOf(":", p + 1);
  358.             if (p2 != -1) {
  359.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  360.             }
  361.  
  362.             p = url.indexOf("%40");
  363.             if (p != -1) {
  364.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  365.             }
  366.  
  367.             return new URL(url);
  368.          } else {
  369.             return new URL(((Applet)this).getCodeBase(), url);
  370.          }
  371.       } catch (MalformedURLException e) {
  372.          System.out.println(e);
  373.          return null;
  374.       }
  375.    }
  376.  
  377.    public void mouseClicked(MouseEvent e) {
  378.    }
  379.  
  380.    public void mouseEntered(MouseEvent e) {
  381.       this.isIn = true;
  382.       if (this.enterText != null) {
  383.          this.isEnterTextEnabled = true;
  384.          ((Component)this).repaint();
  385.       }
  386.  
  387.       if (this.statusBarText != null) {
  388.          ((Applet)this).showStatus(this.statusBarText);
  389.       }
  390.  
  391.       if (this.enterSound != null) {
  392.          this.enterSound.play();
  393.       }
  394.  
  395.       if (this.link != null) {
  396.          ((Component)this).setCursor(new Cursor(12));
  397.       }
  398.  
  399.    }
  400.  
  401.    public void mouseExited(MouseEvent e) {
  402.       this.isIn = false;
  403.       if (this.isEnterTextEnabled) {
  404.          this.isEnterTextEnabled = false;
  405.          ((Component)this).repaint();
  406.       }
  407.  
  408.       if (this.link != null) {
  409.          ((Component)this).setCursor(new Cursor(0));
  410.       }
  411.  
  412.    }
  413.  
  414.    public void mousePressed(MouseEvent e) {
  415.       if (this.clicSound != null) {
  416.          this.clicSound.play();
  417.       }
  418.  
  419.       if (this.link != null) {
  420.          String target = ((Applet)this).getParameter("target");
  421.          if (target == null) {
  422.             target = "_blank";
  423.          }
  424.  
  425.          URL u = this.giveURL(this.link);
  426.          ((Applet)this).getAppletContext().showDocument(u, target);
  427.       }
  428.  
  429.    }
  430.  
  431.    public void mouseReleased(MouseEvent e) {
  432.    }
  433.  
  434.    public void mouseDragged(MouseEvent e) {
  435.    }
  436.  
  437.    public void mouseMoved(MouseEvent e) {
  438.       this.field_4 = e.getX() - this.wiIm / 2;
  439.       this.field_5 = e.getY() - this.heIm / 2;
  440.    }
  441. }
  442.